//
//  ZMZWebContentView.h
//  zmzcloud
//
//  Created by 吴嘉佳 on 2017/7/26.
//  Copyright © 2017年 吴嘉佳. All rights reserved.


#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>

#define ZMZ_JSI_SHARE     @"shareMessage"
#define ZMZ_JSI_PAY       @"payOrder"
#define ZMZ_JSI_CHAT      @"showSendMsg"
#define ZMZ_JSI_register  @"register"
#define ZMZ_JSI_ShareContent @"shareContent"
#define ZMZ_JSI_JumpPage    @"jumpPage"
#define ZMZ_JSI_jumpChat    @"jumpChat"
#define ZMZ_JSI_sendTel     @"sendTel"


@protocol ZMZWebViewActionDelegate <NSObject>

- (void)webViewDidHandleMessageName:(NSString *)messageName messageBody:(id)messageBody;

@end

/*
 * webview加载前，返回YES加载，返回NO不加载
 */
typedef BOOL(^ZMZWebViewShouldStartLoadBlock)(WKWebView *webView,NSURLRequest *request);

/*
 * webview 开始加载
 */
typedef void(^ZMZWebViewDidLoadBlock)(WKWebView *webView);

/*
 * webview 加载结束
 */
typedef void(^ZMZWebViewFinshLoadBlock)(WKWebView *webView);

/*
 * 获取webview加载完成后内容高度
 */
typedef void(^ZMZWebViewContentHeightBlock)(CGFloat height);

/*
 * 加载失败
 */
typedef void(^ZMZWebViewLoadErrorBlock)(WKWebView *webView,NSError *error);
/* 加载进度 */
typedef void(^ZMZWebViewPropressBlock)(CGFloat propress);
/* webview标题 */
typedef void(^ZMZWebViewTitleBlock)(NSString *title);


@interface ZMZWebContentView : UIView

@property (nonatomic ,strong,readonly) WKWebView *webView;

/***
 * webview回调
 */
// 加载前
@property (nonatomic ,copy) ZMZWebViewShouldStartLoadBlock shouldStartLoadBlock;
// 开始加载
@property (nonatomic ,copy) ZMZWebViewDidLoadBlock didLoadBlock;
// 加载结束
@property (nonatomic ,copy) ZMZWebViewFinshLoadBlock finshLoadBlock;
// 加载失败
@property (nonatomic ,copy) ZMZWebViewLoadErrorBlock loadErrorBlock;
// webview高度回调
@property (nonatomic ,copy) ZMZWebViewContentHeightBlock contentHeightBlock;

@property (nonatomic ,copy) ZMZWebViewPropressBlock propressBlock;
@property (nonatomic ,copy) ZMZWebViewTitleBlock titleBlock;

@property (nonatomic, weak) id<ZMZWebViewActionDelegate> delegate;

/*
 * setter
 */
- (void)setShouldStartLoadBlock:(ZMZWebViewShouldStartLoadBlock)shouldStartLoadBlock;
- (void)setDidLoadBlock:(ZMZWebViewDidLoadBlock)didLoadBlock;
- (void)setFinshLoadBlock:(ZMZWebViewFinshLoadBlock)finshLoadBlock;
- (void)setLoadErrorBlock:(ZMZWebViewLoadErrorBlock)loadErrorBlock;
- (void)setContentHeightBlock:(ZMZWebViewContentHeightBlock)contentHeightBlock;

/**
 加载链接

 @param urlString 链接字符串
 */
- (void)loadRequestWithURLString:(NSString *)urlString;

/**
 加载html内容

 @param htmlString 内容字符串
 */
- (void)loadHtmlContentWithHtmlString:(NSString *)htmlString;


/**
 更新userid到cookie中
 */
- (void)updateWebConfigCookieWithUserId:(NSString *)userId;


/**
 移除js接口，必须，不然会造成内存无法释放
 */
- (void)removeJsInterfaces;

@end
